package com.topboya.linker.api;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.topboya.linker.model.response.BaseResponse;
import com.topboya.linker.model.response.ChangePsRespnse;
import com.topboya.linker.model.response.CheckPhoneResponse;
import com.topboya.linker.model.response.CompanyUserListReponse;
import com.topboya.linker.model.response.CreatOrgResponse;
import com.topboya.linker.model.response.CreateDocCustomerResponse;
import com.topboya.linker.model.response.CreateTaskReponse;
import com.topboya.linker.model.response.CustomerByIdResponse;
import com.topboya.linker.model.response.CustomerByOrgIdAndNewlyCusListResopnse;
import com.topboya.linker.model.response.CustomerByOrgIdResponse;
import com.topboya.linker.model.response.DayByYearMothResponse;
import com.topboya.linker.model.response.DeleteTaskResponse;
import com.topboya.linker.model.response.DeptUserResponse;
import com.topboya.linker.model.response.DictByKeyResponse;
import com.topboya.linker.model.response.DictionaryResponse;
import com.topboya.linker.model.response.FeekbackReponse;
import com.topboya.linker.model.response.FileBytaskIdAndProductIdReponse;
import com.topboya.linker.model.response.FileLabelResponse;
import com.topboya.linker.model.response.FollowUserByOfficeResponse;
import com.topboya.linker.model.response.FollowUserLateResponse;
import com.topboya.linker.model.response.HomeListResponse;
import com.topboya.linker.model.response.LatelyDataResponse;
import com.topboya.linker.model.response.MiniSignInResponse;
import com.topboya.linker.model.response.MiniSignOutResopnse;
import com.topboya.linker.model.response.MyNoticeListResponse;
import com.topboya.linker.model.response.NewlyOrgListResponse;
import com.topboya.linker.model.response.OrganizationResopnse;
import com.topboya.linker.model.response.ProductInforListReponse;
import com.topboya.linker.model.response.SelectFileResponse;
import com.topboya.linker.model.response.TaskFileResponse;
import com.topboya.linker.model.response.TaskProductResponse;
import com.topboya.linker.model.response.TaskResponse;
import com.topboya.linker.model.response.TencentLocationResponse;
import com.topboya.linker.model.response.TitleDictResopnse;
import com.topboya.linker.model.response.UpFileResponse;
import com.topboya.linker.model.response.UserDataResponse;
import com.topboya.linker.model.response.VisitTypeResponse;
import com.topboya.linker.model.response.UpdateTaskBackResponse;
import com.topboya.linker.utils.LogUtils;


import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.Field;
import rx.Observable;

/**
 * @创建者 CSDN_LQR
 * @描述 使用Retrofit对网络请求进行配置
 */
public class ApiRetrofit extends BaseApiRetrofit {
    private static final String TAG = "ApiRetrofit-";
    public MyApi mApi;
    public static ApiRetrofit mInstance;

    private ApiRetrofit() {
        super();
        Gson gson = new GsonBuilder()
                .setLenient()
                .create();

        //在构造方法中完成对Retrofit接口的初始化
        mApi = new Retrofit.Builder()
                .baseUrl(MyApi.BASE_URL)
                .client(getClient())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build()
                .create(MyApi.class);
    }

    public static ApiRetrofit getInstance() {
        if (mInstance == null) {
            synchronized (ApiRetrofit.class) {
                if (mInstance == null) {
                    mInstance = new ApiRetrofit();
                }
            }
        }
        return mInstance;
    }

    private RequestBody getRequestBody(Object obj) {
        String route = new Gson().toJson(obj);
        LogUtils.v(TAG + "route:" + route);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("multipart/form-data"), route);
        return body;
    }

    //注册
    public Observable<CheckPhoneResponse> authorize(String loginName, String password, String loginTermType, String captcha) {

        return mApi.authorize(loginName, password, loginTermType, captcha);
    }

    //查询组织列表
    public Observable<OrganizationResopnse> getOrgList(String pageNo,String orgName) {

        return mApi.getOrgList(pageNo,orgName);
    }
    //查询组织列表
    public Observable<OrganizationResopnse> getOrgListMy(String pageNo,String orgName,String delType) {

        return mApi.getOrgListMy(pageNo,orgName,delType);
    }

    //查询组织列表
    public Observable<CustomerByOrgIdResponse> getCustomerByOrgId(String orgId) {

        return mApi.getCustomerByOrgId(orgId);
    }

    //查询用户信息
    public Observable<DictByKeyResponse> getDictByKey(String type) {

        return mApi.getDictByKey(type);
    }

    //查询科室
    public Observable<TitleDictResopnse> getTitleByKey(String type) {

        return mApi.getTitleByKey(type);
    }

    //保存用户信息
    public Observable<CreateDocCustomerResponse> createDoctorCustomer(String orgId ,String id , String cusName, String phone, String department, String posit,String workExperience) {

        return mApi.createDoctorCustomer( orgId ,id,cusName,phone, department,posit,workExperience);
    }


    //查询科室
    public Observable<DictionaryResponse> getOrgTypeFromDic(String type) {

        return mApi.getOrgTypeFromDic(type);
    }
    //查询级别
    public Observable<DictionaryResponse> getHosLevelFromDic(String type) {

        return mApi.getHosLevelFromDic(type);
    }

    //查询区域
    public Observable<DictionaryResponse> getAreaFromDic(String type) {

        return mApi.getHosLevelFromDic(type);
    }
    //查询区域
    public Observable<TencentLocationResponse> getInverseAddressList(String location, String getPoi) {

        return mApi.getInverseAddressList( location, getPoi);
    }

    //查询区域
    public Observable<UpFileResponse> uploadFile(MultipartBody.Part file) {

        return mApi.uploadFile(file);
    }

    //创建终端
    public Observable<CreatOrgResponse> creatOrg(String orgName, String orgAddress, String orgType, String lat, String lon, String addressJson, String hosLevel, String orgAreaId) {

        return mApi.creatOrg(orgName,orgAddress,orgType,lat,lon,addressJson,hosLevel,orgAreaId);
    }

    //查询产品信息
    public Observable<ProductInforListReponse> getProductInforList(String pageNo,String productName,String extendFlag) {

        return mApi.getProductInforList(pageNo,productName,extendFlag);
    }
    //查询最近产品信息
    public Observable<LatelyDataResponse> getLatelyData() {

        return mApi.getLatelyData();
    }
    //    获取一个月中存在任务的日期
    public Observable<DayByYearMothResponse> getDayByYearMoth(String startTime) {

        return mApi.getDayByYearMoth(startTime);

    }
    //    获取具体某一天的任务列表
    public Observable<DeptUserResponse> getDeptUserList() {

        return mApi.getDeptUserList();

    }
//    //    获取具体某一天的任务列表
    public Observable<HomeListResponse> getHomeList(String taskType, String userIdJson, String startTime, String signOutLon, String signOutLat, String pageSize, String pageNo) {

        return mApi.getHomeList(taskType,userIdJson,startTime, signOutLon,signOutLat, pageSize, pageNo);

    }

    //查询任务类型：学术推广，学术拜访等
    public Observable<VisitTypeResponse> getVisitType(String type) {

        return mApi.getVisitType(type);
    }

    //查询资料详情
    public Observable<SelectFileResponse> getProductFileList(String productId,String fileType) {

        return mApi.getProductFileList(productId,fileType);
    }


    public Observable<FollowUserLateResponse> getFollowUser(String type) {

        return mApi.getFollowUser(type);
    }

    public Observable<FollowUserByOfficeResponse> getFollowUserByOffice(String officeId) {

        return mApi.getFollowUserByOffice(officeId);
    }

    public Observable<CreateTaskReponse> createTask(String orgId , String orgName, String createDate, String timeUse, String startTime, String endTime,String cusList, String followName, String followId, String remarks , String Mflage ) {

        return mApi.createTask(orgId ,orgName,createDate,timeUse,startTime,endTime,cusList,followName,followId,remarks ,Mflage);
    }

    public Observable<DeleteTaskResponse> deleteTask(String id) {

        return mApi.deleteTask(id);
    }

    public Observable<MiniSignInResponse> miniSignIn(String lat, String lon, String actLat, String actLon , String operaId) {

        return mApi.miniSignIn( lat,lon, actLat, actLon ,operaId);
    }

    public Observable<FeekbackReponse> getFeekbackLable(String type) {

        return mApi.getFeekbackLable(type);
    }

    public Observable<UpdateTaskBackResponse> updateTaskBack(String sumUp, String feedbackId, String Id, String signOutLat, String signOutLon) {

        return mApi.updateTaskBack( sumUp, feedbackId,Id,signOutLat,signOutLon);
    }

    public Observable<MiniSignOutResopnse> miniSignOut(String id, String operaId, String signOutLat,String signOutLon) {

        return mApi.miniSignOut( id, operaId, signOutLat,signOutLon);
    }

    public Observable<NewlyOrgListResponse> getNewlyOrgList() {

        return mApi.getNewlyOrgList();
    }

//   获取最近拜访的医生
    public Observable<CustomerByOrgIdAndNewlyCusListResopnse> getCustomerByOrgIdAndNewlyCusList(String orgId) {

        return mApi.getCustomerByOrgIdAndNewlyCusList(orgId);
    }


//   获取最近拜访的医生
    public Observable<FileLabelResponse> getFilelableByDicKey(String type) {

        return mApi.getFilelableByDicKey(type);
    }
//   获取公司组织架构
    public Observable<CompanyUserListReponse> getCompanyUserList() {

        return mApi.getCompanyUserList();
    }
    public Observable<TaskProductResponse> getTaskProductList(String id) {

        return mApi.getTaskProductList(id);
    }
    public Observable<TaskFileResponse> getTaskFile(String id) {

        return mApi.getTaskFile(id);
    }

    public Observable<FileBytaskIdAndProductIdReponse> getFeekPruductFileBytaskIdAndProductId(String id ,String productId) {

        return mApi.getFeekPruductFileBytaskIdAndProductId(id,productId);
    }

    public Observable<TaskResponse> getTask(String id ) {

        return mApi.getTask(id);
    }

    public Observable<MyNoticeListResponse> getMyNoticeList(String pageNo) {

        return mApi.getMyNoticeList(pageNo);
    }

    public Observable<MyNoticeListResponse> getNoticeList(String pageNo) {

        return mApi.getNoticeList(pageNo);
    }

    public Observable<CustomerByIdResponse> getCustomerById(String id) {

        return mApi.getCustomerById(id);
    }

    public Observable<ChangePsRespnse> modifyPassWord(String oldPassword, String newPassword) {

        return mApi.modifyPassWord(oldPassword,newPassword);
    }

    public Observable<UserDataResponse> getUserData(){

        return mApi.getUserData();
    }

}
